<template>
    <a-drawer :width="600" title="角色授权" placement="right" :visible="visible" :closable="false" :mask-closable="maskClosable" :destroy-on-close="destroyOnClose" @close="close">
        <Attorney ref="attorneyRef" />
        <template #footer>
            <a-button @click="close">取消</a-button>
            <a-button type="primary" @click="submit">保存</a-button>
        </template>
    </a-drawer>
</template>
<script setup>
import { nextTick, ref } from 'vue'
import { permission } from '/@/api/System/Role'
import { SUCCESS_CODE } from '@iframe/tools/axios/axios'
import { notice } from '@iframe/tools/components'
import { useModal } from '@iframe/tools/mixins/ModelDrawerMixins'
import Attorney from './Attorney.vue'

const { visible, destroyOnClose, maskClosable, close } = useModal()
const attorneyRef = ref()

const submit = () => {
    permission(attorneyRef.value.getForm()).then(result => {
        if (result.code === SUCCESS_CODE) {
            notice.success('赋权成功')
            close()
        }
    })
}

const open = id => {
    visible.value = true
    nextTick(() => {
        attorneyRef.value.setRoleId(id)
    })
}

defineExpose({ open })
</script>
